<?php
namespace app\admin\model;

use think\Model;
use think\Db;
use traits\model\SoftDelete;

class Rank extends Model
{
	use SoftDelete;
	protected $deleteTime = 'delete_time';
	protected $table = 'user_admin';

	/**
	 * 管理员列表
	 * @param  [type]
	 * @return [null | data] 管理员列表
	 */
	public function show()
	{
		//返回用户列表
		return Db::table($this->table)->select();
	}

	/**
	 * 添加管理员
	 * @param  [type]
	 * @return [null | data] bool
	 */
	public function createRank($name, $password)
	{
		// return $name;
		$admin_user = Db::table($this->table)->where('name', $name)->find();
		if ($admin_user) {
			return false;
		}
		$data = [
			'name' => $name,
			'password' => $password,
			'token' => $name.$_SERVER["REMOTE_ADDR"],
			'create_time' => date('Y-m-d H:i:s')
		];
		return Db::table($this->table)->insert($data);
	}

	/**
	 * 修改管理员
	 * @param  [type]
	 * @return [null | data] bool
	 */
	public function updateRank($id, $name, $password)
	{
		$data = [
			'name' => $name,
			'password' => $password,
			'update_time' => date('Y-m-d H:i:s')
		];
		return Db::table($this->table)->where('id', $id)->update($data);
	}

	/**
	 * 删除管理员(软删除)
	 * @param  [type]
	 * @return [null | data] bool
	 */
	public function deleteRank($id)
	{
		return Db::table($this->table)->where('id', $id)->delete();
	}

	
	/**
	 * 查询个人信息
	 * @param  [type]
	 * @return [null | data] data
	 */
	public function adminFind($id)
	{
		return Db::table($this->table)->where('id', $id)->find();
	}	
}